package com.retail.xiaocui.server.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.retail.common.log.annotation.Log;
import com.retail.common.log.enums.BusinessType;
import com.retail.common.security.annotation.RequiresPermissions;
import com.retail.xiaocui.common.domain.Warning;
import com.retail.xiaocui.server.service.WarningService;
import com.retail.common.core.web.controller.BaseController;
import com.retail.common.core.domain.Result;
import com.retail.common.core.utils.poi.ExcelUtil;
import com.retail.common.core.web.page.TableDataInfo;

/**
 * 预警列信息Controller
 *
 * @author retail
 * @date 2024-03-01
 */
@RestController
@RequestMapping("/warning")
public class WarningController extends BaseController
{
    @Autowired
    private WarningService warningService;

    /**
     * 查询预警列信息列表
     */
    @RequiresPermissions("xiaocui:warning:list")
    @GetMapping("/list")
    public TableDataInfo list(Warning warning)
    {
        startPage();
        List<Warning> list = warningService.selectWarningList(warning);
        return getDataTable(list);
    }

    /**
     * 导出预警列信息列表
     */
    @RequiresPermissions("xiaocui:warning:export")
    @Log(title = "预警列信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Warning warning)
    {
        List<Warning> list = warningService.selectWarningList(warning);
        ExcelUtil<Warning> util = new ExcelUtil<Warning>(Warning.class);
        util.exportExcel(response, list, "预警列信息数据");
    }

    /**
     * 获取预警列信息详细信息
     */
    @RequiresPermissions("xiaocui:warning:query")
    @GetMapping(value = "/{warningId}")
    public Result getInfo(@PathVariable("warningId") Long warningId)
    {
        return success(warningService.selectWarningByWarningId(warningId));
    }

    /**
     * 新增预警列信息
     */
    @RequiresPermissions("xiaocui:warning:add")
    @Log(title = "预警列信息", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody Warning warning)
    {
        return toAjax(warningService.insertWarning(warning));
    }

    /**
     * 修改预警列信息
     */
    @RequiresPermissions("xiaocui:warning:edit")
    @Log(title = "预警列信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody Warning warning)
    {
        return toAjax(warningService.updateWarning(warning));
    }

    /**
     * 删除预警列信息
     */
    @RequiresPermissions("xiaocui:warning:remove")
    @Log(title = "预警列信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{warningIds}")
    public Result remove(@PathVariable Long[] warningIds)
    {
        return toAjax(warningService.deleteWarningByWarningIds(warningIds));
    }
}
